package sword_to_1;

import node.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_34 {
    public static void main(String[] args) {

    }
    private static List<List<Integer>> pathSum(TreeNode root, int target) {
        List<List<Integer>> ans = new ArrayList<>();
        dfs(root, 0, target, new ArrayList<>(), ans);
        return ans;
    }
    private static void dfs(TreeNode node, int now, int goal, List<Integer> list, List<List<Integer>> ans){
        if (node == null){
            return;
        }
        now += node.val;
        list.add(node.val);
        if (node.left == null && node.right == null){
            if (now == goal){
                ans.add(list);
            }
        }
        dfs(node.left, now, goal, new ArrayList<>(list), ans);
        dfs(node.right, now, goal, new ArrayList<>(list), ans);
    }
}
